package cn.yza.算法.Others;



import java.util.HashSet;
import java.util.Scanner;

/** 链表去重
 * @author Honglixi
 * @create 2021-12-10 15:35
 */
public class test01 {
    private static class Node{//单链表结点定义
        private Node next;
        private Object data;

        public Node(Object data) {//构造器
            this.data = data;
        }
    }
    //利用hash去重
    public static void remove(Node first) {
        HashSet<Object> hashSet = new HashSet<>();
        Node p = first.next;
        Node pre = first;
        while (p != null) {
            //删除重复元素
            if (hashSet.contains(p.data)) {
                pre.next = p.next;
            } else {
                //加入到hash表中
                hashSet.add(p.data);
            }
            pre = pre.next;
            p = p.next;
        }
    }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);//链表元素输入
        int len=scanner.nextInt();//输入要输入元素的个数
        int []a=new int [len];
        for (int i = 0; i <len ; i++) {
            a[i]=scanner.nextInt();
        }
        Node first=new Node(null);//建立哑元
        Node p=first;//数组转链表
        for (int i = 0; i <len ; i++) {
            p.next=new Node(a[i]);
            p=p.next;
        }
        //  remove(first);//hash去重
        remove(first);//二重循环去重
        Node p1=first.next;//链表打印
        while (p1!=null)
        {
            System.out.println(p1.data);
            p1=p1.next;
        }
    }
}
